function Slideshow() {
    this.slideshowContainer;
    this.listBigs;
    this.listThumbs;
    this.listBigsWrapper;
    this.listThumbsWrapper;
    this.arrowLeft;
    this.arrowRight;
    this.myThumbsScroll;
    this.myBigScroll;
    this.itemClicked = -1;
    this.thumbsWidth = 0;
    this.mediaWidth;
    this.mediaHeight;
    this.thumbsHeight;
    this.bigsHeight;
    this.bigsWidth;
    this.paginationEl;
    this.heightMode;
    this.isThumbsUsed;
    this.scrollDuration = 500;
    this.isOmnitureCalled;
    this.OmnitureSection;
    this.isOmnitureCalledAtInit;
    this.lastPageX = -1;
    this.initSlideshow = function(a, d) {
        var e = {thumbs: true,heightMode: "default",callOmniture: false,omnitureSection: "",isOmnitureCalledAtInit: true};
        var c = this;
        var b = $.extend({}, e, d);
        this.isThumbsUsed = b.thumbs;
        this.heightMode = b.heightMode;
        this.isOmnitureCalled = b.callOmniture;
        this.isOmnitureCalledAtInit = b.isOmnitureCalledAtInit;
        this.OmnitureSection = b.omnitureSection;
        this.slideshowContainer = $(a);
        if (this.slideshowContainer.attr("data-loaded")) {
            return false
        }
        this.slideshowContainer.attr("data-loaded", "true");
        this.buildArchitecture();
        this.initializeScroll();
        this.resizeContainer();
        if (this.isThumbsUsed) {
            this.linkThumbsToBig()
        }
        $(window).resize(function() {
            var f = $(c.slideshowContainer).is(":visible");
            if (f) {
                c.resizeContainer()
            }
        })
    };
    this.scrollEndCallback = function() {
        if (this.itemClicked >= 0) {
            this.myThumbsScroll.scrollToElement("li:nth-child(" + this.itemClicked + ")", this.scrollDuration);
            this.myBigScroll.currPageX = this.itemClicked - 1;
            this.itemClicked = -1
        } else {
            this.listThumbs.find(".focus").removeClass("focus");
            this.listBigs.find(".focus").removeClass("focus");
            if (this.isThumbsUsed) {
                this.myThumbsScroll.scrollToElement("li:nth-child(" + (this.myBigScroll.currPageX + 1) + ")", this.scrollDuration);
                this.listThumbs.find("li:nth-child(" + (this.myBigScroll.currPageX + 1) + ")").addClass("focus")
            }
            this.listBigs.find("li:nth-child(" + (this.myBigScroll.currPageX + 1) + ")").addClass("focus")
        }
        if (this.myBigScroll.currPageX != 0) {
            this.arrowLeft.fadeIn("slow")
        } else {
            this.arrowLeft.fadeOut("slow")
        }
        if (this.myBigScroll.currPageX != this.myBigScroll.pagesX.length - 1) {
            this.arrowRight.fadeIn("slow")
        } else {
            this.arrowRight.fadeOut("slow")
        }
        if (this.heightMode == "parent") {
            if (this.isThumbsUsed) {
                this.listBigsWrapper.height(this.slideshowContainer.get(0).getBoundingClientRect().height - this.listThumbsWrapper.get(0).getBoundingClientRect().height - 6 + "px")
            } else {
                this.listBigsWrapper.height(this.slideshowContainer.get(0).getBoundingClientRect().height + "px")
            }
        } else {
            this.listBigsWrapper.height(this.listBigsWrapper.find("img").get(0).getBoundingClientRect().height + "px")
        }
        if (this.paginationEl) {
            this.paginationEl.html((this.myBigScroll.currPageX + 1) + "/" + this.myBigScroll.pagesX.length)
        }
        if (this.isOmnitureCalledAtInit) {
            this.lastPageX = 0
        }
        if (this.isOmnitureCalled && this.lastPageX >= 0) {
            var a = (this.myBigScroll.currPageX + 1);
            callOmnitureUrlWithParams({pos: "Slideshow",evt: categoryParam + " Slideshow " + this.OmnitureSection + " " + a,lid: categoryParam + " Slideshow " + this.OmnitureSection})
        }
        this.lastPageX = 0
    };
    this.resizeContainer = function() {
        this.mediaWidth = this.slideshowContainer.get(0).getBoundingClientRect().width;
        this.mediaWidth = this.slideshowContainer.width();
        this.mediaHeight = this.slideshowContainer.get(0).getBoundingClientRect().height;
        this.mediaHeight = this.slideshowContainer.height();
        if (this.isThumbsUsed) {
            this.listThumbsWrapper.height(this.listThumbsWrapper.find("img").get(0).getBoundingClientRect().height + "px");
            this.thumbsHeight = this.listThumbsWrapper.height()
        }
        this.listBigsWrapper.height(this.mediaHeight - this.thumbsHeight - 6);
        this.listBigsWrapper.find("li").width(this.mediaWidth);
        this.bigsHeight = this.listBigsWrapper.height();
        this.bigsWidth = this.listBigsWrapper.width();
        var a = this;
        this.listBigsScroller.css("width", this.listBigs.find("li").length * this.mediaWidth);
        this.listBigs.find("li img:visible").each(function() {
            a.sizeAndPlaceImgs($(this));
            $(this).bind("load", function() {
                a.sizeAndPlaceImgs($(this))
            })
        });
        if (this.isThumbsUsed) {
            this.myThumbsScroll.refresh()
        }
        this.myBigScroll.refresh();
        this.myBigScroll.scrollToElement("li:nth-child(" + (this.myBigScroll.currPageX + 1) + ")", 100)
    };
    this.linkThumbsToBig = function() {
        var a = this;
        a.thumbsWidth = 0;
        this.listThumbs.find("li img").each(function() {
            var c = $(this);
            var b = Math.round(c.get(0).getBoundingClientRect().width) + "px";
            c.parent().css("width", b);
            a.thumbsWidth += c.parent().get(0).getBoundingClientRect().width;
            a.listThumbsScroller.width(Math.round(a.thumbsWidth) + "px");
            a.myThumbsScroll.refresh()
        });
        this.listThumbs.find("li:first-child").addClass("focus");
        this.arrowLeft.hide();
        if (this.listThumbsWrapper.attr("data-clickable") == "true") {
            var a = this;
            this.listThumbsWrapper.find("li").each(function() {
                $(this).click(function() {
                    a.listThumbs.find(".focus").removeClass("focus");
                    $(this).addClass("focus");
                    a.itemClicked = $(this).prevAll().length + 1;
                    la('slideshowThumbsClick', 'home', a.itemClicked)
                    a.myBigScroll.scrollToElement("li:nth-child(" + ($(this).prevAll().length + 1) + ")", 500)
                })
            })
        }
    };
    this.sizeAndPlaceImgs = function(a) {
        a.css("top", parseInt((this.bigsHeight - a.get(0).getBoundingClientRect().height) / 2) + "px");
        a.css("left", parseInt((this.bigsWidth - a.get(0).getBoundingClientRect().width) / 2) + "px");
        this.myBigScroll.refresh()
    };
    this.buildArchitecture = function() {
        this.wrapBigList();
        if (this.isThumbsUsed) {
            this.wrapThumbList()
        } else {
            this.buildPagination()
        }
        this.buildArrows()
    };
    this.wrapBigList = function() {
        this.listBigs = this.slideshowContainer.find(".bigs");
        this.listBigsScroller = this.listBigs.wrap("<div/>").parent();
        this.listBigsScroller.addClass("scroller scollerBigs");
        this.listBigsWrapper = this.listBigsScroller.wrap("<div/>").parent();
        this.listBigsWrapper.addClass("wrapper wrapperBigs")
    };
    this.wrapThumbList = function() {
        this.listThumbs = this.slideshowContainer.find(".thumbs");
        this.listThumbsScroller = this.listThumbs.wrap("<div/>").parent();
        this.listThumbsScroller.addClass("scroller scollerThumbs");
        this.listThumbsWrapper = this.listThumbsScroller.wrap("<div/>").parent();
        this.listThumbsWrapper.addClass("wrapper wrapperThumbs").attr("data-clickable", "true")
    };
    this.buildArrows = function() {
        this.arrowRight = new $("<div>").addClass("rightArrowSlideshow");
        this.arrowLeft = new $("<div>").addClass("leftArrowSlideshow");
        this.listBigsWrapper.append(this.arrowLeft).append(this.arrowRight);
        this.buildArrowEvents()
    };
    this.buildArrowEvents = function() {
        var a = this;
        this.arrowLeft.click(function() {
            a.myBigScroll.scrollToPage("prev")
            la('slideshowArrow', 'home', 'Left');
        });
        this.arrowRight.click(function() {
            a.myBigScroll.scrollToPage("next")
            la('slideshowArrow', 'home', 'Right');
        })
    };
    this.buildPagination = function() {
        this.paginationEl = new $("<span>").addClass("position");
        this.slideshowContainer.append(this.paginationEl)
    };
    this.initializeScroll = function() {
        this.myBigScroll = new iScroll(this.listBigsWrapper.get(0), {
          snap: true,momentum: false,
          hScrollbar: false,
          onScrollEnd: this.scrollEndCallback.bind(this)});
        if (this.isThumbsUsed) {
            this.myThumbsScroll = new iScroll(this.listThumbsWrapper.get(0), {snap: true,hScrollbar: false,vScroll: false})
        }
    }
};
